package com.chw.admin.storage;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chw.annotation.PermissionSecurity;
import com.chw.common.ServiceData;
import com.chw.utils.LogUtil;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;

@Controller
@RequestMapping({ "/out" })
public class ChwOutstorageController {
	private static LogUtil log = LogUtil.newInstance(ChwOutstorageController.class);

	@Autowired
	private IChwOutstorageService chwOutstorageService;

	@RequestMapping(value = { "/find.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "查询", module = "物料出库", btnfunc = "find")
	public ServiceData find(HttpServletRequest request, ChwOutstorage chwOutstorage, Integer currentPage, Integer pageSize)
			throws Exception {
		ServiceData ret = new ServiceData();
		PageInfo<ChwOutstorage> chw = this.chwOutstorageService.findEntity(chwOutstorage, currentPage, pageSize);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/getEntityById.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "根据id查询", module = "物料出库", btnfunc = "getEntityById")
	public ServiceData getEntityById(HttpServletRequest request, String id) throws Exception {
		ServiceData ret = new ServiceData();
		ChwOutstorage chw = this.chwOutstorageService.getEntityById(id);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/save.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "新增", module = "物料出库", btnfunc = "save")
	public ServiceData save(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		ChwOutstorage chwOutstorage = (ChwOutstorage) gson.fromJson(param, ChwOutstorage.class);
		int i = this.chwOutstorageService.addEntity(chwOutstorage);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/update.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "修改", module = "物料出库", btnfunc = "update")
	public ServiceData update(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		ChwOutstorage chwOutstorage = (ChwOutstorage) gson.fromJson(param, ChwOutstorage.class);
		int i = this.chwOutstorageService.updateEntity(chwOutstorage);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/delete.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "删除", module = "物料出库", btnfunc = "delete")
	public ServiceData delete(HttpServletRequest request, String id) throws Exception {
		ServiceData ret = new ServiceData();
		int i = this.chwOutstorageService.deleteEntity(id);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}
}